package com.bustle.web.mbean.request;

import java.util.Date;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import com.bustle.ejb.entity.Payment;
import com.bustle.ejb.service.OrderManager;
import com.bustle.web.mbean.session.CartMBean;

@ManagedBean
@RequestScoped
public class PaymentMBean
{
  public String pay()
  {
    Payment payment = orderManager.payOrder(cartMBean.getOrderId());
    return WelcomeMBean.SCREEN;
  }

  public int getCardNumber()
  {
    return cardNumber;
  }

  public void setCardNumber(int aCardNumber)
  {
    cardNumber = aCardNumber;
  }

  public Date getExpirationDate()
  {
    return expirationDate;
  }

  public void setExpirationDate(Date aExpirationDate)
  {
    expirationDate = aExpirationDate;
  }

  public int getCryptogram()
  {
    return cryptogram;
  }

  public void setCryptogram(int aCryptogram)
  {
    cryptogram = aCryptogram;
  }

  public double getPrice()
  {
    return orderManager.computePaymentPrice(cartMBean.getOrderId());
  }

  public void setCartMBean(CartMBean aCartMBean)
  {
    cartMBean = aCartMBean;
  }

  protected int cardNumber;
  protected Date expirationDate;
  protected int cryptogram;

  @EJB
  protected OrderManager orderManager;

  @ManagedProperty("#{cartMBean}")
  protected CartMBean cartMBean;

  static public final String SCREEN = "payment.jsf";
}
